<?php
require_once ("../src/db/connectdatabase.php");
function getSearchLoanInVN($mucdich, $country) {
	$con = new ConnectDB();
	
	$sql = "SELECT l.idlvn, l.bankid, b.bankname, b.banklogo, l.namepurpose, l.address, l.contentinfo, l.contentinfobasic FROM banks AS b, loaninvietnam AS l WHERE b.bankid=l.bankid AND l.idpurpose LIKE '%".$mucdich."%' AND l.address LIKE '%".$country."%' AND l.isuse=1 ORDER BY l.datecreate DESC";
	return $con -> getvalueString($sql);
}

function getDetailLoanInVN($id) {
	$con = new ConnectDB();
	
	$sql = "SELECT l.idlvn, l.bankid, b.bankname, b.banklogo, l.namepurpose, l.address, l.contentinfo, l.content, l.contentinfobasic FROM banks AS b, loaninvietnam AS l WHERE b.bankid=l.bankid AND l.idlvn='".$id."' AND l.isuse=1";
	return $con -> getvalueString($sql);
}


$action = $_POST['act'];
if($action == 'load') {
	if(isset($_POST['typeloan']) && isset($_POST['contry'])) {
		$mucdich = $_POST['typeloan'];
		$contry = $_POST['contry'];
		
		$arrdata = getSearchLoanInVN($mucdich, $contry);
		echo json_encode($arrdata);
	}
} else if($action == 'detail') {
	if(isset($_POST['p'])) {
		$id = $_POST['p'];
		
		$arrdata = getDetailLoanInVN($id);
		if(count($arrdata) > 0) {
			echo json_encode($arrdata[0]);
		} else {
			echo json_encode('null');
		}
	}
}
?>